package com.jch.dm.chapter_23_interpreter;

import java.util.ArrayList;

/**
 * @author: Administrator
 * <command list> ::= <command>* end
 * @create: 2020/04/14 18:16
 **/
public class CommandListNode extends Node {

    private ArrayList list = new ArrayList();

    /**
     * 解析
     *
     * @param context
     * @throws ParseException
     */
    @Override
    public void parse(Context context) throws ParseException {
        while(true){
            if (context.currentToken() == null) {
                throw new ParseException("Missing 'end'");
            }else if (context.currentToken().equals("end")){
                context.skipToken("end");
                break;
            }else{
                Node commandNode = new CommandNode();
                commandNode.parse(context);
                list.add(commandNode);
            }
        }
    }

    @Override
    public String toString(){
        return list.toString();
    }
}
